//
//  AddBoilingView.swift
//  Juejin App Demo
//
//  Created by 葛鹏 on 2021/8/30.
//

import SwiftUI

struct AddBoilingView: View {
    
    @State private var multipleText: String = ""
    
    @State private var textEditorTapped: Bool = false
    
    @State private var imagePickerPresented: Bool = false
    
    @State private var images: [UIImage] = []
        
    var body: some View {
        ZStack(alignment: .bottom){
            ScrollView{
                LazyVStack{
                    
                    if textEditorTapped{
                        TextEditor(text: $multipleText).frame(height: 100).padding()
                        
                    } else {
                        Text("告诉你个秘密，发布沸点不能少于5个字哦，另外添加合适话题会被更多掘友们看见呦~").frame(height: 100).foregroundColor(.gray).padding().onTapGesture {
                            textEditorTapped = true
                        }
                    }
                    
                    let columns: [GridItem] =
                             Array(repeating: .init(.flexible()), count: 3)
                    ScrollView {
                        LazyVGrid(columns: columns) {
                        Button(action: {
                            imagePickerPresented = true
                        }, label: {
                            ZStack{
                                Rectangle().foregroundColor(Color(red: 248/255, green: 248/255, blue: 248/255))
                                Rectangle().strokeBorder(style:StrokeStyle(lineWidth: 2.5, lineCap: .round, lineJoin: .round, miterLimit: 1, dash: [10], dashPhase: 0)).aspectRatio(1, contentMode: .fit)
                                Image(systemName: "plus").font(.system(size: 50))
                                
                            }.foregroundColor(.gray).padding(1.5)
                        }).sheet(isPresented: $imagePickerPresented, content: {
                            ImagePicker(images: $images)
                        })
                        ForEach((0..<images.count), id: \.self) {index in
                            
                            let uiImage = images[index]
                            
                            Image(uiImage: uiImage).resizable().aspectRatio(1, contentMode: .fit)
                            
                            }
                        }.font(.largeTitle)
                    }.padding()
                    
                    
                    HStack{
                        Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                            ZStack{
                                RoundedRectangle(cornerRadius: 15).stroke().frame(width: 125, height: 35)
                                HStack{
                                    Text("添加话题")
                                    Image(systemName: "chevron.right")
                                }.padding()
                            }
                        })
                        Spacer()
                    }.padding()
                    
                    
                    
                    
                    
                }
            }.navigationTitle("发布沸点").navigationBarItems(trailing: Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                Text("发布")
            })).navigationBarTitleDisplayMode(.inline)
            ZStack{
                Rectangle().foregroundColor(Color(red: 250/250, green: 250/250, blue: 250/250)).frame(height: 50)
                HStack{
                    Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                        Image(systemName: "photo")
                    })
                    Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/, label: {
                        Image(systemName: "link")
                    }).disabled(true)
                    Spacer()
                }
            }.padding(.horizontal)
            
        }
        
    }
}

struct AddBoilingView_Previews: PreviewProvider {
    static var previews: some View {
        AddBoilingView()
    }
}
